package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppRankDept;
import com.ruoyi.background.service.IAppRankDeptService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 部门排名表Controller
 *
 * @author ruoyi
 * @date 2024-08-23
 */
@RestController
@RequestMapping("/applet/deptRank")
public class AppRankDeptController extends BaseController {
    @Autowired
    private IAppRankDeptService appRankDeptService;

    /**
     * 查询部门排名表列表
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppRankDept appRankDept) {
        startPage();
        List<AppRankDept> list = appRankDeptService.selectAppRankDeptList(appRankDept);
        return getDataTable(list);
    }

    /**
     * 导出部门排名表列表
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:export')")
    @Log(title = "部门排名表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppRankDept appRankDept) {
        List<AppRankDept> list = appRankDeptService.selectAppRankDeptList(appRankDept);
        ExcelUtil<AppRankDept> util = new ExcelUtil<AppRankDept>(AppRankDept.class);
        util.exportExcel(response, list, "部门排名表数据");
    }

    /**
     * 获取部门排名表详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appRankDeptService.selectAppRankDeptById(id));
    }

    /**
     * 新增部门排名表
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:add')")
    @Log(title = "部门排名表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppRankDept appRankDept) {
        return toAjax(appRankDeptService.insertAppRankDept(appRankDept));
    }

    /**
     * 修改部门排名表
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:edit')")
    @Log(title = "部门排名表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppRankDept appRankDept) {
        return toAjax(appRankDeptService.updateAppRankDept(appRankDept));
    }

    /**
     * 删除部门排名表
     */
    @PreAuthorize("@ss.hasPermi('applet:deptRank:remove')")
    @Log(title = "部门排名表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appRankDeptService.deleteAppRankDeptByIds(ids));
    }
}
